<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*"%>
<jsp:useBean id="dbConnection" scope="page" class="DB.DBConnection"/>
<html>
<title>
	209ChatRoom
</title>
<link href="CSS/style.css" rel="stylesheet">
	<script language="JavaScript">
  	function DoTest(){
		var name,pwd,selectedroom;
		name = document.form1.username.value
		pwd = document.form1.userpwd.value
		selectedroom = document.form1.room.value
		if(name=="")
		{
			alert("请输入正确的用户名！");
			document.form1.username.focus();
			return false;
		}
		if(name.charAt(0) > '~')
		{
			alert("请将您的“输入法编辑器 (IME)”切换成半角的 ASCII 设置，然后重新输入您的用户名！");
			document.form1.username.focus();
			return false;
		}
		if(!pwd)
		{
			alert("请输入您的密码！");
			document.form1.userpwd.focus();
			return false;
		}
		if(!selectedroom)
		{
			alert("请选择一个房间进入");
			document.form1.room.focus();
			return false;
		}
		form1.action="loginaction.jsp"	
	}
	function reg(){
		window.navigate("/209ChatRoom/reg.jsp");
	}
  </script>
<body>
<br>
<form name="form1" method="post" action="">
    <table width="363" height="224"  border="0" align="center" cellpadding="0" cellspacing="0" background="images/login.png">
      <tr>
        <td height="100" colspan="3" class="word_dark"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="363" height="100"><param name="movie" value="images/top.swf">
          <param name="quality" value="high">
          <embed src="top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="363" height="100"></embed>
        </object></td>
      <tr>
		<td width="216" align="center" valign="top" class="word_dark">用户名:
		<input type=text name=username value="" onClick="SelText();">
		</td>
      </tr>
      <tr>
        <td width="216" align="center" valign="top" class="word_dark">密&nbsp; 码: 
        <input type=password name=userpwd value="">
        </td>
      </tr>
      <tr>
        <td width="216" align="center" valign="top" class="word_dark">聊天室:
			<select name="room" lang="zh" onChange="ShowRoom();">
		<script>
		document.write("<option value=''selected>聊天房间</option>")
<%
	dbConnection.getConnection();
  	String sql="select * from room";
  	ResultSet rs=dbConnection.executeQuery(sql);
  	
  	while(rs.next()){
%>
		document.write("<option value='<%=rs.getString("Id")%>'><%=rs.getString("room_name")%></option>")
<%}
  dbConnection.closeConn();//调用DBConnection关闭数据库连接方法
%>
		</script>
			</select>
		</td>
      </tr>
      <tr>
        <td width="94" align="center" valign="top" class="word_dark">
        	<input name="提交" type=submit value="登录" onclick="DoTest();">
        	<input name="注册" type="button" value="注册" onclick="reg();">
        </td>       
      </tr>
</table>		
</form>
	<script language="javascript">
	function BodyOnload()
	{
		if(document.form1.username)
		{
			document.form1.username.focus();
			document.form1.username.select();
		}
	}
	function SelText()
	{
		if (document.form1.username.value == "<请输入您的用户名>")
		{
			document.form1.username.value = "";
		}
	
	}
	BodyOnload();	
	</script>
</body>
</html>
